package com.haoshuang.zhouzhoubang.ui.page.message

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.MessageStatisticsBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData


class MessageViewModel : BaseViewModel() {

    /**
     * 消息统计
     */
    val getMessageCountData = StatefulMutableLiveData<ResponseBean<MessageStatisticsBean>>()
    fun getMessageCount() = netRequest {
        start { getMessageCountData.value = StateData.Loading }
        request { ApiRepo.getMessageCount()  }
        success { getMessageCountData.value = StateData.Success(it) }
        error { code, msg ->
            getMessageCountData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 设置消息全部已读
     */
    val doMessageReadData = StatefulMutableLiveData<Any>()
    fun doMessageRead(type: Int) = netRequest {
        start { doMessageReadData.value = StateData.Loading }
        request { ApiRepo.doMessagesRead(type)  }
        success { doMessageReadData.value = StateData.Success(it.data) }
        error { code, msg ->
            doMessageReadData.value = StateData.Error(code, msg)
        }
    }

}